<?php
/**
 * Project: AIGC
 * Author: moufer <moufer@163.com>
 * Date: 2024/7/31 10:56
 */

namespace module\user\enum;

use mof\annotation\Description;
use mof\concern\EnumExtend;

enum VipPeriodEnum: string
{
    use EnumExtend;

    #[Description('年')]
    case YEAR = 'year';

    #[Description('月')]
    case MONTH = 'month';

    #[Description('周')]
    case WEEK = 'week';

    #[Description('日')]
    case DAY = 'day';

    public static function contact(mixed $value, mixed $getAttr): string
    {
        $unit = match ($getAttr) {
            self::YEAR->value => '年',
            self::MONTH->value => '个月',
            self::WEEK->value => '周',
            self::DAY->value => '日',
            default => $getAttr,
        };
        return sprintf('%s%s', $value, $unit);
    }

    public function getFutureTime(int $value, int $startTime): bool|int
    {
        $unit = $this->value;
        return strtotime("+$value $unit", $startTime);
    }

    public function getPastTime(int $value, int $startTime): bool|int
    {
        $unit = $this->value;
        return strtotime("-$value $unit", $startTime);
    }
}
